<!--  -->
<template>
  <el-form ref="form" label-position="right" label-width="100px" :model="formData" :rules="rules">
    <el-form-item label="终止原因" prop="processValue">
      <el-radio-group v-model="formData.processValue">
        <el-radio v-for="v in itemTerminationReason" :key="v.id" :label="v.value">
          {{ v.name }}
        </el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="终止说明" prop="remark">
      <el-input v-model="formData.remark" type="textarea" rows="5" />
    </el-form-item>
    <el-form-item class="t-r">
      <el-button type="primary" size="mini" @click="submit">
        提交
      </el-button>
    </el-form-item>
  </el-form>

</template>

<script>
import ProjectAPI from '@/apis/project';
import { mapActions, mapState, } from 'vuex';
export default {
  name: 'End',
  components: {
  },
  props: {
    visible: Boolean,
  },
  data() {
    return {
      formData: {
        processValue: '',
        itemCode: '',
        remark: '',
      },
      rules: {
        processValue: [{
          required: true,
          message: '请选择',
          trigger: 'change',

        }],
        remark: [{
          required: true,
          message: '说明不能为空',
          trigger: 'change',
        }],
      },

    };
  },
  computed: {
    ...mapState('project/index', ['itemCode']),
    ...mapState({

      itemTerminationReason: (v) => {
        return v['dictionary'].itemTerminationReason;
      },
    }),
  },
  mounted() {
  },
  methods: {
    // itemTerminationReason
    ...mapActions('project/index', ['FETCH_PERFORM_EVENT']),
    close() {
      this.$emit('update:visible', false);
    },
    async  submit() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          try {
            this.formData.itemCode = this.itemCode;
            await ProjectAPI.base.endProject(this.formData);
            this.$emit('done');
          } catch (e) {
            this.$message.error(e);
          }
        }
      });
    },
  },
};
</script>
<style lang='scss' scoped>
.t-r{
  text-align: right;
}
</style>
